package edu.gdkm.account;

public class Account {
    private String bankNumber;
    private String password;
    private String name;
    private String idNumber;
    private double balance;









    public String getBankNumber() {
        return bankNumber;
    }

    public void setBankNumber(String bankNumber) {

        if(bankNumber.length()!=14){
            System.out.println("请输入14位账号");
        }else{
            char[] chars = bankNumber.toCharArray();
            boolean flag=false;
            for (int i = 0; i < chars.length; i++) {
                if(chars[i]<'0'||chars[i]>'9'){
                    flag=true;
                    break;
                }
            }
            if(flag){
                System.out.println("请输入14位数字的账号");
            }else{
                this.bankNumber = bankNumber;
            }
        }

    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if(password.matches("\\d{6}")){
            this.password = password;
        }else{
            System.out.println("请输入6位数字密码");
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        if(idNumber.matches("\\d{17}[0-9Xx]")){
            this.idNumber=idNumber;
        }else{
            System.out.println("请输入正确的身份证号码");
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }



    public void income(double money){
        if(money>0){
            this.balance=this.balance+money;
        }

    }

    public double takeout(double money){
        if(this.balance>money){
            this.balance=this.balance-money;
        }else{
            money=this.balance;
            this.balance=0;
        }
        return money;
    }
    public void display(){
        System.out.println("---------------------------");
        System.out.println("账号：" + this.getBankNumber() +
                "\n户主姓名：" + this.getName() +
                "\n身份证号：" + this.getIdNumber() +
                "\n余额：" + this.getBalance());
        System.out.println("---------------------------");
    }

    public boolean transfer(Account account,double money){
        if(this.getBalance()<money){
            System.out.println("余额不足");
            return false;
        }else{
            this.setBalance(this.getBalance()-money);
            account.setBalance(account.getBalance()+money);
            return true;
        }

    }
    public boolean transfer2(Account account,double money){
        if(this.getBalance()<money){
            System.out.println("余额不足");
            return false;
        }else{
           this.takeout(money);
           account.income(money);
            return true;
        }
    }
}
